import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Practice02_c3p0 {
    public static void main(String[] args) {
        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        System.out.println(comboPooledDataSource);

        try (Connection connection = comboPooledDataSource.getConnection()) {
            // 使用连接执行数据库操作
            System.out.println(connection);
            //执行SQL语句
            PreparedStatement statement = connection.prepareStatement("select * from account");
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                double balance = resultSet.getDouble("balance");
                String commit  = resultSet.getString("commit");
                System.out.println("编号：" + id + ",余额：" + balance + ",备注：" + commit);
            }
            resultSet.close();
            statement.close();
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            comboPooledDataSource.close();
        }
    }
}
